import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CamerasRand {

	FileWriter fw;
	BufferedWriter bw;
	PrintWriter pw;
	StringBuilder sb = new StringBuilder();
	Random rand = new Random();
	String temp;
	String name = "cameras.csv";
	String[] camera_model = { "Coolpix", "Cyber-Shot", "PowerShot", "SB", "WB",
			"DualView", "FinePix", "D", "EOS", "Rebel T", "K", "Alpha", "" };
	String[] camera_brand = { "Sony", "Canon", "Leica", "Kodak", "Nikon",
			"Pentax", "Fujifilm", "Panasonic", "Polaroid", "Olympus",
			"Vivitar", "HP" };
	int camera_model_size = camera_model.length;
	int camera_brand_size = camera_brand.length;
	List<Node> camera = new ArrayList<Node>();
	List<Node> camcorder = new ArrayList<Node>();

	public void RandCamera() throws IOException {
		int i = randInt(camera_model_size - 1);
		int j = randInt(camera_brand_size - 1);
		double pixels = 0;
		while (pixels < 5)
			pixels = randDouble(25) + (double) (randDouble(99) / 100);
		String brand = camera_brand[i];
		String model = camera_model[j] + " " + randLetter();
		int fps = fps_gen();
		double price = 0;
		while (price < 80) {
			price = randDouble(1000);
			int random = rand.nextInt(2);
			if (random == 1)
				price += 0.50;
			else
				price += 0.99;
		}
		for (int k = 0; k < camera.size(); k++) {
			if (camera.size() == 0) {
				break;
			}
			else if (model != camera.get(k).model) {
				Node randNode = new Node(model, brand, pixels, fps, price);
				camera.add(randNode);
				System.out.println(randNode.brand);
				break;
			}
		}
	}

	/*
	public void RandCamcorder() throws IOException {
		int i = randInt(camera_model_size - 1);
		int j = randInt(camera_brand_size - 1);
		double pixels = 0;
		while (pixels < 5)
			pixels = randDouble(25) + (double) (randDouble(99) / 100);
		String brand = camera_brand[i];
		String model = camera_model[j] + " " + randLetter();
		int fps = fps_gen();
		double price = 0;
		while (price < 80) {
			price = randDouble(1000);
			int random = rand.nextInt(2);
			if (random == 1)
				price += 0.50;
			else
				price += 0.99;
		}
		for (int k = 0; k < camera_model_size; k++) {
			if (model != camcorder.get(k).model) {
				Node randNode = new Node(model, brand, pixels, fps, price);
				camcorder.add(randNode);
				break;
			}
		}
	}
	*/

	public int randInt(int size) {
		return rand.nextInt(size);
	}

	public String randLetter() {
		String[] alphabet = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
				"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
				"w", "x", "y", "z" };
		return alphabet[rand.nextInt(alphabet.length)].toUpperCase()
				+ alphabet[rand.nextInt(alphabet.length)].toUpperCase()
				+ rand.nextInt(900);
	}

	public int fps_gen() {
		int x = 0;
		while (x == 0) {
			x = rand.nextInt(5);
		}
		if (x == 1)
			return 15;
		else if (x == 2)
			return 30;
		else if (x == 3)
			return 60;
		else
			return 120;
	}

	public double randDouble(int size) {
		double generated;
		return (double) rand.nextInt(size); // + (rand.nextInt()%100);
	}

	public void fileCreate(String name) throws IOException {
		fw = new FileWriter(name);
	}

	public void fileWrite() throws IOException {
		bw = new BufferedWriter(new FileWriter(name));
		pw = new PrintWriter(bw);
		String s;
		pw.write("Hello");
		System.out.println(camera.get(0).model); //NOT BEING Added

		for (int i = 0; i < camera.size(); i++) {
			pw.write(camera.get(i).model);
			pw.write(",");
			pw.write(camera.get(i).brand);
			pw.write(",");
			sb.append(camera.get(i).pixels);
			temp = sb.toString();
			bw.write(temp);
			sb = new StringBuilder();
			bw.write(",");
			sb.append(camera.get(i).fps);
			temp = sb.toString();
			bw.write(temp);
			sb = new StringBuilder();
			bw.write(",");
			sb.append(camera.get(i).price);
			temp = sb.toString();
			bw.write(temp);
			sb = new StringBuilder();
			pw.println();
			pw.flush();
		}
		/*
		for (int i = 0; i < camcorder.size(); i++) {
			pw.write(camcorder.get(i).model);
			pw.write(",");
			pw.write(camcorder.get(i).brand);
			pw.write(",");
			sb.append(camcorder.get(i).pixels);
			temp = sb.toString();
			bw.write(temp);
			sb = new StringBuilder();
			bw.write(",");
			sb.append(camcorder.get(i).fps);
			temp = sb.toString();
			bw.write(temp);
			sb = new StringBuilder();
			bw.write(",");
			sb.append(camcorder.get(i).price);
			temp = sb.toString();
			bw.write(temp);
			sb = new StringBuilder();
			pw.println();
			pw.flush();
		}
		*/
		
		bw.close();
	}

}
